package com.property.demo.dto;

import com.property.demo.model.ParkingUsage;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
@NoArgsConstructor
public class ParkingUsageDTO {
    private Long id;
    
    // Parking info
    private Long parkingId;
    private String parkingCode;
    private String parkingName;
    private String parkingType;
    
    // Owner info
    private Long ownerId;
    private String ownerName;
    private String ownerPhone;
    
    // Vehicle info
    private Long vehicleId;
    private String carNumber; // 车牌号
    
    // Community info
    private Long communityId;
    private String communityName;
    
    // Usage info
    private String usageType;
    private Date startDate;
    private Date endDate;
    private Double fee;
    private String paymentStatus;
    private String remarks;
    private Date createdAt;
    private Date updatedAt;
    
    public ParkingUsageDTO(ParkingUsage parkingUsage) {
        this.id = parkingUsage.getId();
        
        // Set parking info
        if (parkingUsage.getParking() != null) {
            this.parkingId = parkingUsage.getParking().getId();
            this.parkingName = parkingUsage.getParking().getName();
            this.parkingCode = parkingUsage.getParking().getName(); // Using name as code
            this.parkingType = parkingUsage.getParking().getType();
            
            // Set community info if available
            if (parkingUsage.getParking().getCommunity() != null) {
                this.communityId = parkingUsage.getParking().getCommunity().getId();
                this.communityName = parkingUsage.getParking().getCommunity().getName();
            }
        }
        
        // Set owner info
        if (parkingUsage.getOwner() != null) {
            this.ownerId = parkingUsage.getOwner().getId();
            this.ownerName = parkingUsage.getOwner().getName();
            this.ownerPhone = parkingUsage.getOwner().getPhoneNumber();
        }
        
        // Set vehicle info
        if (parkingUsage.getVehicle() != null) {
            this.vehicleId = parkingUsage.getVehicle().getId();
            this.carNumber = parkingUsage.getVehicle().getLicensePlate();
        }
        
        // Set usage info
        if (parkingUsage.getUsageType() != null) {
            switch (parkingUsage.getUsageType()) {
                case 1:
                    this.usageType = "租用";
                    break;
                case 2:
                    this.usageType = "购买";
                    break;
                case 3:
                    this.usageType = "临时";
                    break;
                default:
                    this.usageType = "未知";
            }
        }
        this.startDate = parkingUsage.getStartDate();
        this.endDate = parkingUsage.getEndDate();
        this.fee = parkingUsage.getFee();
        this.paymentStatus = parkingUsage.getPaymentStatus();
        this.remarks = parkingUsage.getRemarks();
        this.createdAt = parkingUsage.getCreatedAt();
        this.updatedAt = parkingUsage.getUpdatedAt();
    }
} 